import React from 'react';
import ItemInput from '../itemcomponent/ItemInput';

/*
const validateForLength = (l = 100) => 
  (v = '') => {
    if (v.length > l) {
      return {
        valid: false,
        msg: `请不要输入超过${l}个字符`,
      };
    }
    return { valid: true };
  };
*/
const TextConfig = (props) => {
  const {
    className = '',
    selectedItem = {},
    getInputViewValue = () => { },
    onChange = () => { },
    onBlur = () => { },

  } = props;
  return (
    <React.Fragment>
      <ItemInput
        className={className}
        label='默认值：'
        value={getInputViewValue('defaultValue', selectedItem.defaultValue)}
        onChange={(value) => onChange('defaultValue', value)}
        onBlur={(value) => { onBlur('defaultValue', value, true) }}
        maxLength={100}
        // onBlur={(value = '') => { onBlur('defaultValue', value.slice(0,100), true) }}
        // validate={validateForLength(100)}
      />
      <ItemInput
        className={className}
        label='提示信息：'
        value={getInputViewValue('placeholder', selectedItem.placeholder)}
        onChange={(value) => onChange('placeholder', value)}
        onBlur={(value) => { onBlur('placeholder', value, true) }}
        maxLength={20}
        // onBlur={(value = '') => { onBlur('placeholder', value.slice(0,20), true) }}
        // validate={validateForLength(20)}
      />
    </React.Fragment>
  );
}

export default TextConfig;